package java_learn.java_jinjie.DataStructure;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 李浩然
 * @Date: 2020/12/4 11:16 下午
 * java.util.LinkedHashMap<K,V> entends HashMap<K,V>
 * Map 接口的哈希表和链接列表实现，具有可预知的迭代顺序。
 * 底层原理:
 * 哈希表+链表(记录元素的顺序)
 */
public class DemoLinkedHashMap {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("4", "a");
        map.put("b", "b");
        map.put("c", "c");
        map.put("d", "d");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }
        java.util.LinkedHashMap<String, String> linkedHashMap = new java.util.LinkedHashMap<>();
        linkedHashMap.put("4", "a");
        linkedHashMap.put("b", "b");
        linkedHashMap.put("c", "c");
        linkedHashMap.put("d", "d");
        for (Map.Entry<String, String> entry : linkedHashMap.entrySet()) {
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }
    }
}
